//
//  CYEditNicknameViewController.m
//  cyydt
//
//  Created by chu on 2019/1/16.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYEditNicknameViewController.h"

@interface CYEditNicknameViewController ()

@end

@implementation CYEditNicknameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self rightBarItemWithTitle:@"保存"];
    if (self.type == EditType_nickname) {
        self.nicknameTF.placeholder = @"请输入昵称";
        self.nicknameTF.text = [YLUserInfo shareUserInfo].nickname;
    }else if (self.type == EditType_areaName){
        self.indiaLabel.hidden = YES;
        self.nicknameTF.placeholder = @"请输入您的姓名";
    }else if (self.type == EditType_phone){
        self.indiaLabel.hidden = YES;
        self.nicknameTF.placeholder = @"请输入您的手机号";
    }else{
        self.indiaLabel.hidden = YES;
        self.nicknameTF.placeholder = @"请输入年龄";
        self.nicknameTF.text = [YLUserInfo shareUserInfo].name;
    }
}

- (void)RighttouchEvent{
    if (self.type == EditType_areaName || self.type == EditType_nickname) {
        if (self.nicknameTF.text.length < 2 || self.nicknameTF.text.length > 10) {
            [self.view makeToast:@"长度2-10个字符" duration:1.5 position:CSToastPositionCenter];
            return;
        }
    }
    if (self.type == EditType_areaName || self.type == EditType_phone) {
        if (_delegate && [_delegate respondsToSelector:@selector(saveWithValue:EditType:)]) {
            [_delegate saveWithValue:self.nicknameTF.text EditType:self.type];
            [[AppDelegate sharedAppDelegate] popViewController];
        }
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"user/update"];
    NSDictionary *param = @{@"nickname":self.nicknameTF.text};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"修改用户信息 ---- %@",responseResult);
        
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                [[AppDelegate sharedAppDelegate] getUserInfosWithComplecation:^{
                    [[AppDelegate sharedAppDelegate] popViewController];
                }];

            }else{
                [self.view makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
    
}

@end
